/***************************************************************
**
** baum.do
**
** Replication file for table 1 in:
**   Honaker and King, 2010, "What To Do about Missing Values in
**   Time-Series Cross-Section Data" 
**
** This file first "tsset"'s the data and generates a set of 
**   lags and leads in each of 10 imputed datasets and in the 
**   incomplete data.  Then finally runs the analysis.
**
** Requires the "miest.ado" file for combining results across
**   multiple imputations
**
** jH, 23/2/10 
***************************************************************/


set mem 30m

/**************************************************************/

insheet using "h1.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew1.dta", replace
clear

/**************************************************************/

insheet using "h2.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew2.dta", replace
clear

/**************************************************************/

insheet using "h3.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew3.dta", replace
clear

/**************************************************************/

insheet using "h4.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew4.dta", replace
clear

/**************************************************************/

insheet using "h5.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew5.dta", replace
clear

/**************************************************************/

insheet using "h6.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew6.dta", replace
clear

/**************************************************************/

insheet using "h7.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew7.dta", replace
clear

/**************************************************************/

insheet using "h8.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew8.dta", replace
clear

/**************************************************************/

insheet using "h9.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew9.dta", replace
clear

/**************************************************************/

insheet using "h10.csv"
encode countrycode, gen(panelcode)
tsset panelcode year

drop temprich temprichdem
gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

save "hnew10.dta", replace
clear

/**************************************************************/

insheet using "baummergenona.csv"   /* This is a .csv version of the raw dataset with missing value codes for Stata */
encode countrycode, gen(panelcode)
tsset panelcode year

gen flag1=polity2 > -11.5
gen flag2=polity2 > -6.5
gen flag3=polity2 >  0.5
gen flag4=polity2 >  5.5

gen polity3=flag1 + flag2 + flag2 + flag4
recode polity3 4=. if polity2==.

drop polity2
gen polity2=polity3

gen loggdppc=log(gdppc)
gen logpoptot=log(poptot)
gen rich=gdppc>2500
gen richdem=rich*polity2
gen poordem=(1-rich)*polity2

gen l1check= countrycode==countrycode[_n-1]

gen l5check= countrycode==countrycode[_n-5]
recode l5check 0=.
gen leadcheck= countrycode==countrycode[_n+1]
recode leadcheck 0=.

gen leadfemlifeex=femlifeex[_n+1]*leadcheck
gen leadfemschool=femschool[_n+1]*leadcheck
gen l5richdem=richdem[_n-5]*l5check
gen l5poordem=poordem[_n-5]*l5check

gen l1femlifeex=femlifeex[_n-1]*l1check
gen l1femschool=femschool[_n-1]*l1check




/*************************************************/
/**** This is finally the analysis in Table 1 ****/ 
/*************************************************/

log using "baumlog.log", replace

xtregar femlifeex loggdppc logpoptot rich l5richdem l5poordem, re
xtregar femschool loggdppc logpoptot rich l5richdem l5poordem, re

clear 

miest hnew xtregar femlifeex loggdppc logpoptot rich l5richdem l5poordem, re nsets(10)
miest hnew xtregar femschool loggdppc logpoptot rich l5richdem l5poordem, re nsets(10)

log off
